﻿<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Untitled Page" %>

<%@ Register TagPrefix="Club" TagName="WebContent" Src="~/UserControls/WebContent.ascx" %>

<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="~/UserControls/LoginBanner.ascx" %>
<%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="~/UserControls/ImageThumbnail.ascx" %>
<script runat="server">
    Function privatelabel(ByVal isprivate As Boolean) As String
        If isprivate Then
            Return "Album is private"
        Else
            Return "Album is not private"
        End If
    End Function

    
    Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
        If User.Identity.IsAuthenticated Then
            e.Command.Parameters("@ownerid").Value = Membership.GetUser().ProviderUserKey
        Else
            Throw New Exception("User must be authenticated to create an album")
        End If
    End Sub
    
    
    Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
        Response.Redirect("list.aspx")
    End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="body">
        <Club:LoginBanner ID="LoginBanner1" runat="server" />
        <div id="columnleft">
            <a name="content_start" id="content_start"></a>
            <div class="leftblock">
                <Club:WebContent id="cms1" runat="server" Section="photos" />
            </div>
        </div>
        <div id="columnright">
            <div class="rightblock">
                <h2>
                    Add new Album</h2>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubsiteDB %>"
                    SelectCommand="SELECT title, ownerid, private FROM albums WHERE (albumid = @albumid)"
                    InsertCommand="INSERT INTO Albums(title, parentid, ownerid, private) VALUES (@title, @parentid, @ownerid, @private)"
                    OldValuesParameterFormatString="{0}" OnInserting="SqlDataSource1_Inserting" OnInserted="SqlDataSource1_Inserted">
                    <SelectParameters>
                        <asp:Parameter Name="albumid" />
                    </SelectParameters>
                    <InsertParameters>
                        <asp:Parameter Name="title" />
                        <asp:Parameter Name="parentid" DefaultValue="0" />
                        <asp:Parameter Name="ownerid" />
                        <asp:Parameter Name="private" />
                    </InsertParameters>
                </asp:SqlDataSource>
                <asp:FormView ID="FormView1" runat="server" DataSourceID="Sqldatasource1" Width="445px"
                    DefaultMode="Insert">
                    <InsertItemTemplate>
                        <table>
                            <tr>
                                <td>
                                    Album Name</td>
                                <td>
                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("title") %>' /></td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td>
                                    <asp:CheckBox ID="CheckBox1" runat="server" Text="Album is private and non visible to other users"
                                        Checked='<%#Bind("Private") %>' /></td>
                            </tr>
                        </table>
                        <div style="text-align: right">
                            <Club:RolloverButton ID="GreenRolloverButton2" CommandName="Insert" Text="Add Album"
                                runat="server" />
                            <Club:RolloverLink ID="GreenRolloverButton3" NavigateURL="~/photo/list.aspx" Text="Cancel"
                                runat="server" />
                        </div>
                    </InsertItemTemplate>
                </asp:FormView>
            </div>
        </div>
        <div class="clear2column"></div>
    </div>
</asp:Content>
